﻿<%@ Page Language="C#" Inherits="TPG.SharePoint.Workflow.BulkTaskPage, TPG.SharePoint.Workflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3a33f5f62ef53ef" %>
<%@ Register TagPrefix="tpg" Namespace="TPG.SharePoint.Workflow.Controls" Assembly="TPG.SharePoint.Workflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3a33f5f62ef53ef" %>
<%@ Assembly Name="TPG.SharePoint.Workflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d3a33f5f62ef53ef" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="TPG.SharePoint.Workflow" %>
<%@ Import Namespace="$rootnamespace$" %>

<%--add assembly reference here--%>
<%--<%@ Assembly Name="MyWorkflowLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken= " %>--%>

<asp:content id="PageTitle" contentplaceholderid="PlaceHolderPageTitle" runat="server">
</asp:content>

<asp:content id="PageTitleInTitleArea" contentplaceholderid="PlaceHolderPageTitleInTitleArea" runat="server">
</asp:content>

<asp:content id="PageDescription" contentplaceholderid="PlaceHolderPageDescription" runat="server">
</asp:content>

<asp:content id="Main" contentplaceholderid="PlaceHolderMain" runat="server">
    <asp:Repeater ID="Tasks" runat="server">
        <HeaderTemplate>
            <table>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td valign="top" style="width: 100%;">
                    <asp:HiddenField ID="Id" Value='<%# Eval("ListItemId") %>' runat="server" />
                    <asp:Label ID="Label1" Text='<%# Eval("ItemDisplayName") %>' runat="server" />
                </td>                                
                <td valign="top" style="white-space: nowrap;">
                    <asp:DropDownList ID="Action" runat="server">
                        <asp:ListItem Text="None" />
                        <asp:ListItem Text="Action1" />
                        <asp:ListItem Text="Action2" />
                    </asp:DropDownList>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
    <asp:Button Text="Ok" OnClick="OkButton_Click" runat="server" />
    <asp:Button Text="Cancel" OnClick="CancelButton_Click" runat="server" />
</asp:content>

<script runat="server" type="text/C#">
protected override void OnLoad(EventArgs e)
{
    if (IsInitialLoad)
    {
        Tasks.DataSource = GetTaskItems();
        Tasks.DataBind();
    }
}
    
protected void OkButton_Click(object sender, EventArgs e)
{
    // create a new list of results
    TaskItemCollection results = new TaskItemCollection(TaskContentType);
    results.AllowExtendedProperties = true; // only set if using extended properties
    
    // process each task in the list
    foreach (RepeaterItem item in Tasks.Items)
    {
        /* --- Replace this code with your own code to store any data in the task -- */
        string result = (item.FindControl("Action") as DropDownList).SelectedValue;
        if (result != "None")
        {
            int id = int.Parse((item.FindControl("Id") as HiddenField).Value);
            TaskItem taskItem = results.NewTaskItem(id);
            taskItem["CustomActionField"] = result;                
        }
        /* --- End Code Block -- */
    }
    
    CommitTaskItems(results);
}

protected void CancelButton_Click(object sender, EventArgs e)
{
    CancelTaskItems();
}
</script>

